<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">概要</label>
        <el-input v-model="query.svrTitle" clearable placeholder="概要" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户编号</label>
        <el-input v-model="query.svrCustNo" clearable placeholder="客户编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户名称</label>
        <el-input v-model="query.svrCustName" clearable placeholder="客户名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">服务状态</label>
        <el-input v-model="query.svrStatus" clearable placeholder="服务状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="服务类型" prop="svrType">
            <el-select v-model="form.svrType" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.svr_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="概要" prop="svrTitle">
            <el-input v-model="form.svrTitle" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户编号" prop="svrCustNo">
            <el-input v-model="form.svrCustNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户名称" prop="svrCustName">
            <el-input v-model="form.svrCustName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="服务状态" prop="svrStatus">
            <span style="color: aqua;">{{ form.svrStatus="新创建" }}</span>
          </el-form-item>
          <el-form-item label="服务请求" prop="svrRequest">
            <el-input v-model="form.svrRequest" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item v-show="false" label="创建人编号" prop="svrCreateId">
            {{ form.svrCreateId=user.id }}
          </el-form-item>
          <el-form-item label="创建人" prop="svrCreateBy">
            <span style="color: aqua;">{{ user.nickName }} {{ form.svrCreateBy= user.username }}</span>
          </el-form-item>
          <el-form-item v-show="false" label="创建时间">
            {{ form.svrCreateDate= new Date() }}

          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="svrId" label="编号" />
        <el-table-column prop="svrType" label="服务类型">
          <template slot-scope="scope">
            {{ dict.label.svr_type[scope.row.svrType] }}
          </template>
        </el-table-column>
        <el-table-column prop="svrTitle" label="概要" />
        <el-table-column prop="svrCustNo" label="客户编号" />
        <el-table-column prop="svrCustName" label="客户名称" />
        <el-table-column prop="svrStatus" label="服务状态">
          <template slot-scope="scope">
            {{ dict.label.svr_status[scope.row.svrStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="svrRequest" label="服务请求" />
        <el-table-column prop="svrCreateId" label="创建人编号" />
        <el-table-column prop="svrCreateBy" label="创建人名称" />
        <el-table-column prop="svrCreateDate" label="创建时间" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import crudSctService from '@/api/sctService'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { svrId: null, svrType: null, svrTitle: null, svrCustNo: null, svrCustName: null, svrStatus: null, svrRequest: null, svrCreateId: null, svrCreateBy: null, svrCreateDate: null, svrDueId: null, svrDueTo: null, svrDueDate: null, svrDeal: null, svrDealId: null, svrDealBy: null, svrDealDate: null, svrResult: null, svrSatisfy: null, isDelete: null }
export default {
  name: 'SctService',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['svr_type', 'svr_status', 'cust_satisfy'],
  cruds() {
    return CRUD({ queryOnPresenterCreated: false, title: '客户服务', url: 'api/sctService', idField: 'svrId', sort: 'svrId,desc', crudMethod: { ...crudSctService }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'sctService:add'],
        edit: ['admin', 'sctService:edit'],
        del: ['admin', 'sctService:del']
      },
      rules: {
        svrType: [
          { required: true, message: '服务类型不能为空', trigger: 'blur' }
        ],
        svrTitle: [
          { required: true, message: '概要不能为空', trigger: 'blur' }
        ],
        svrCustNo: [
          { required: true, message: '客户编号不能为空', trigger: 'blur' }
        ],
        svrCustName: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        svrStatus: [
          { required: true, message: '服务状态不能为空', trigger: 'blur' }
        ],
        svrRequest: [
          { required: true, message: '服务请求不能为空', trigger: 'blur' }
        ],
        svrCreateId: [
          { required: true, message: '创建人编号不能为空', trigger: 'blur' }
        ],
        svrCreateBy: [
          { required: true, message: '创建人名称不能为空', trigger: 'blur' }
        ],
        isDelete: [
          { required: true, message: '逻辑删除不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'svrTitle', display_name: '概要' },
        { key: 'svrCustNo', display_name: '客户编号' },
        { key: 'svrCustName', display_name: '客户名称' },
        { key: 'svrStatus', display_name: '服务状态' },
        { key: 'svrDueId', display_name: '分配给的员工编号' },
        { key: 'svrDueTo', display_name: '分配给的员工姓名	' },
        { key: 'svrSatisfy', display_name: '满意度' }
      ]
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
    this.crud.params = { svrStatus: '新创建' }
    this.crud.toQuery()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
